package edu.hawaii.duedates;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;

/**
 * TestDuesDates is a unit test for the DueDates class that checks for valid user input.
 * 
 * @author Team Purple John Ancheta Daniel Arakaki Mari-Lee Flestado
 * 
 * @version 1.1, October 14, 2008
 */
public class TestDueDates {

  /** Instance variable for user id, instantiated to take in command argument. */
  private static final String id = System.getProperties().getProperty("uhm.id");

  /** Instance variable for user last name, instantiated to take in command argument. */
  private static final String lastName = System.getProperties().getProperty("uhm.lastname");

  /**
   * This method will check if uhm is true.
   */
  @Test
  public void testIsUhmOptionTrue() {
    DueDates dueDate = new DueDates();
    assertTrue("This should be true", dueDate.isUhmOption("-uhm"));
  }

  /**
   * This method will check if uhm is false.
   */
  @Test
  public void testIsUhmOptionFalse() {
    DueDates dueDate = new DueDates();
    assertFalse("This should be false", dueDate.isUhmOption(null));
  }

  /**
   * Tests for valid ID and last name with UH library.
   */
  @Test
  public void testGetUhValidEntry() {
    DueDates dueDates = new DueDates();
    try {
      dueDates.getUhmInfo(id, lastName);
    }
    catch (Exception e) {
      fail("Unexpected exception thrown, problem with getUhmInfo.");
    }
  }

  /**
   * Tests for valid ID and invalid last name for UH library.
   * 
   * @throws Exception An exception is thrown should a user not enter a last name.
   */
  @Test(expected = Exception.class)
  public void testUhGetValidId() throws Exception {
    DueDates dueDate = new DueDates();
    String aLastName = null;
    
    dueDate.getUhmInfo(id, aLastName);
    fail("Should never reach here...");
    
  }

  /**
   * Tests for invalid ID and valid last name for UH library.
   * 
   * @throws Exception An exception is thrown should a user not enter an ID.
   */
  @Test(expected = Exception.class)
  public void testUhGetValidLastName() throws Exception {
    DueDates dueDate = new DueDates();
    String anId = null;
    dueDate.getUhmInfo(anId, lastName);
    fail("Should never reach here...");
  }

  /**
   * Tests for invalid ID and last name for UH library.
   * 
   * @throws Exception An exception is thrown should a user not enter an ID or last name.
   */
  @Test(expected = Exception.class)
  public void testUhGetInvalidEntry() throws Exception {
    DueDates dueDate = new DueDates();
    String id = null;
    String lastName = null;

    dueDate.getUhmInfo(id, lastName);
  }

  /**
   * Testing the DueDate.getSiteInfo with -uhm option.
   */
  @Test
  public void testGetSiteInfoUhmOption() {
    try {
      DueDates.getSiteInfo("-uhm", id, lastName);
    }
    catch (Exception e) {
      fail("Unexpected exception thrown, problem with getSiteInfo.");
    }
  }

  /**
   * Testing the DueDate.getSiteInfo with no -uhm option.
   *
   * @throws Exception An exception is thrown for non -uhm option.
   */
  @Test(expected = Exception.class)
  public void testGetSiteInfoNonUhmOption() throws Exception {
    DueDates.getSiteInfo(null, id, lastName);
  }
}
